package top.shiyiri.map;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author Aunean
 * @date 2022/1/6
 */
/*
Properties 常用来处理配置文件。key和value都是String类型
 */
public class PropertiesTest {

    public static void main(String[] args) {

        Properties properties = new Properties();
        FileInputStream stream = null;
        try {
            stream = new FileInputStream("jdbc.properties");
            properties.load(stream);//加载流对应的文件

        } catch (IOException e) {
            e.printStackTrace();
        }

        String name = properties.getProperty("user");
        String password = properties.getProperty("password");
        System.out.println(name + ": " + password);

        //关闭流
        try {
            assert stream != null;
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
